from datetime import datetime

from greatwall.models import Stage
from greatwall.models import Card
from greatwall.src import card_ctrl

class StageOperations(object):

    def __init__(self):
        self.card_ops = card_ctrl.CardOperations()        

    def create_stage(self, wall=None, title='', order_no=0, desc=''):
        stage = Stage()
        stage.fk_wall = wall
        stage.title = title
        stage.order_no = order_no
        #stage.date_created = datetime.today()
        stage.description = desc
        stage.save()
        return stage

    def get_stage_by_id(self, stage_id):
        stage = Stage.objects.get(id=stage_id)
        return stage        

    def get_stage_by_order_no(self, wall, order_no):
        stage = Stage.objects.filter(fk_wall=wall, order_no=order_no)
        if stage:
            return stage[0]
        return None

    def create_dummy_stages(self, wall):
        start_stage = self.create_stage(wall=wall, title='Dummy', order_no=1,
                                        desc='dummy starting stage')
        self.card_ops.create_dummy_card(stage=start_stage, title='start1')
        self.card_ops.create_dummy_card(stage=start_stage, title='start2')
        dev_stage = self.create_stage(wall=wall, title='Coding', order_no=2, 
                                      desc='dummy coding stage')
        self.card_ops.create_dummy_card(stage=dev_stage, title='code1')
        done_stage = self.create_stage(wall=wall, title='Done', order_no=3, 
                                       desc='dummy done stage')
        self.card_ops.create_dummy_card(stage=done_stage, title='done1')

